// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PROD_SAVED_PRODUCT_TECHNIC_ITEM
// * CreateDate    : 2011/8/16 10:16:41
// * Creater       : CodeSmith
// * LastChangeDate: 2011/8/16 10:16:41
// * LastChanger   : 2011/8/16 10:16:41
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Prod
{
/// <summary>
    /// ProdSavedProductTechnicItem
    /// </summary>
    public partial class ProdSavedProductTechnicItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objProdSavedProductTechnicItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static ProdSavedProductTechnicItemEntity GetProdSavedProductTechnicItem(ProdSavedProductTechnicItemEntity objProdSavedProductTechnicItemEntity)
        {
            return DataAccess.SelectSingle<ProdSavedProductTechnicItemEntity>(objProdSavedProductTechnicItemEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objProdSavedProductTechnicItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertProdSavedProductTechnicItem(ProdSavedProductTechnicItemEntity objProdSavedProductTechnicItemEntity)
        {
            return DataAccess.Insert(objProdSavedProductTechnicItemEntity);
        }

        public static bool InsertProdSavedProductTechnicItem(List<ProdSavedProductTechnicItemEntity> objProdSavedProductTechnicItemEntityList)
        {
            return DataAccess.Insert(objProdSavedProductTechnicItemEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objProdSavedProductTechnicItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateProdSavedProductTechnicItem(ProdSavedProductTechnicItemEntity objProdSavedProductTechnicItemEntity)
        {
            return DataAccess.Update(objProdSavedProductTechnicItemEntity);
        }

        public static bool UpdateProdSavedProductTechnicItem(List<ProdSavedProductTechnicItemEntity> objProdSavedProductTechnicItemEntityList)
        {
            return DataAccess.Update<ProdSavedProductTechnicItemEntity>(objProdSavedProductTechnicItemEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objProdSavedProductTechnicItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteProdSavedProductTechnicItem(ProdSavedProductTechnicItemEntity objProdSavedProductTechnicItemEntity)
        {
            return DataAccess.Delete(objProdSavedProductTechnicItemEntity);
        }

        public static bool DeleteProdSavedProductTechnicItem(List<ProdSavedProductTechnicItemEntity> objProdSavedProductTechnicItemEntityList)
        {
            return DataAccess.Delete<ProdSavedProductTechnicItemEntity>(objProdSavedProductTechnicItemEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetProdSavedProductTechnicItemAll()
        {
            return DataAccess.SelectAllDataSet<ProdSavedProductTechnicItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<ProdSavedProductTechnicItemEntity> GetProdSavedProductTechnicItemAllList()
        {
            return DataAccess.SelectAll<ProdSavedProductTechnicItemEntity>();
        }
        #endregion

        #region Functions
        public static List<ProdSavedProductTechnicItemEntity> GetListAllByProductTechnicID(string ProductTechnicID)
        {
            if (string.IsNullOrEmpty(ProductTechnicID))
                return null;
            string Sql = @"SELECT * FROM PROD_SAVED_PRODUCT_TECHNIC_ITEM WHERE PRODUCT_TECHNIC_ID='" + ProductTechnicID + "' ";
            return DataAccess.Select<ProdSavedProductTechnicItemEntity>(Sql);
        }

        public static DataTable GetProdSavedProductTechnicItemByCondition(string condition, string orderBy)
        {
            string sql = @"SELECT A.SEQUENCE,A.GROUP_ID,MWG.GROUP_NAME,
                        B.TECHNIC_NAME,B.TECHNIC_CODE,B.DESCRIPTION,B.DELETE_FLAG,B.STATION_TYPE 
                        FROM PROD_SAVED_PRODUCT_TECHNIC_ITEM A 
                        LEFT JOIN PROD_TECHNIC B ON A.TECHNIC_ID=B.TECHNIC_ID 
                        LEFT JOIN MST_WORKING_GROUP MWG ON A.GROUP_ID=MWG.GROUP_ID 
                        WHERE 1=1";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }
        
        public static List<ProdSavedProductTechnicItemEntity> GetFlowBySavedProductTechnic(ProdSavedProductTechnicEntity mProdSavedProductTechnic)
        {
            string sql = @"SELECT B.* FROM PROD_SAVED_PRODUCT_TECHNIC A 
                LEFT JOIN PROD_SAVED_PRODUCT_TECHNIC_ITEM B ON A.PRODUCT_TECHNIC_ID=B.PRODUCT_TECHNIC_ID 
                WHERE 1=1 AND A.PRODUCT_TECHNIC_ID='" + mProdSavedProductTechnic.ProductTechnicId + "' ";
            return DataAccess.Select<ProdSavedProductTechnicItemEntity>(sql);
        }

        public static List<ProdTechnicEntity> GetProdSavedFlowStation(string condition, string orderBy)
        {
            string sql = @"SELECT C.*
                FROM PROD_SAVED_PRODUCT_TECHNIC A
                LEFT JOIN PROD_SAVED_PRODUCT_TECHNIC_ITEM B ON A.PRODUCT_TECHNIC_ID=B.PRODUCT_TECHNIC_ID
                LEFT JOIN PROD_TECHNIC C ON B.TECHNIC_ID=C.TECHNIC_ID 
                WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            return DataAccess.Select<ProdTechnicEntity>(sql);
        }

//        public static DataTable GetDtFlowTemplate(string ProductTechnicID)
//        {
//            if (string.IsNullOrEmpty(ProductTechnicID))
//                return null;
//            string Sql = @"SELECT PSPTI.*,MWG.GROUP_NAME,MWG.GROUP_ID,'' AS GROUP_PERSON,'' AS PLAN_WORKING_HOURS,
//                PT.TECHNIC_NAME,PT.TECHNIC_CODE,PT.DESCRIPTION
//                FROM PROD_SAVED_PRODUCT_TECHNIC_ITEM PSPTI LEFT JOIN PROD_TECHNIC PT ON PSPTI.TECHNIC_ID=PT.TECHNIC_ID
//                LEFT JOIN MST_WORKING_GROUP MWG ON PSPTI.GROUP_ID=MWG.GROUP_ID 
//                WHERE PSPTI.PRODUCT_TECHNIC_ID='" + ProductTechnicID + "' ";
//            Sql += " ORDER BY PSPTI.SEQUENCE ";
//            DataSet ds = DataAccess.SelectDataSet(Sql);
//            if (ds != null && ds.Tables[0].Rows.Count > 0)
//                return ds.Tables[0];
//            else return null;
//        }

        #endregion
    }
	
	
}	

